package com.tencreat.service.pay.impl;

import com.tencreat.common.enums.*;
import com.tencreat.common.enums.mall.AllEnum;
import com.tencreat.common.event.PaySuccessEvent;
import com.tencreat.common.utils.RabbitSendUtils;
import com.tencreat.domain.account.MallUser;
import com.tencreat.domain.mall.MallGoods;
import com.tencreat.domain.mall.MallGoodsNorms;
import com.tencreat.domain.mall.MallOrder;
import com.tencreat.domain.mall.MallOrderGoods;
import com.tencreat.service.mall.IMallGoodsService;
import com.tencreat.service.mall.IMallOrderGoodsService;
import com.tencreat.service.pay.TradeService;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * 商城订单支付成功回调
 *
 * @author zixin
 * @company 深圳腾创互联科技有限公司
 * @link https://tencreat.com
 * @date 2023/1/2 14:33
 */

@Service
@RequiredArgsConstructor
public class ShopPaySuccessListener implements ApplicationListener<PaySuccessEvent> {

    private final RabbitSendUtils rabbitUtils;
    private final TradeService tradeService;

    @Override
    public void onApplicationEvent(PaySuccessEvent paySuccessEvent) {
        MallOrder order = (MallOrder) paySuccessEvent.getSource();
        if (order.getOrderType() != OrderType.QR_CODE_ORDER) {
            return;
        }
        // 分润
        MallOrderGoods orderGoods = new MallOrderGoods();
        orderGoods.setOrderSn(order.getOrderSn());
        tradeService.orderGoodsIncome(orderGoods);
    }
}
